import Mock from 'mockjs'

Mock.mock(/\/mock\/distribution.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  let num = 32-(body.page-1)*5
  num = num >5?5:num
  console.log(num)
    const data = Mock.mock({
    
        [`list|${num}`]: [{
         check:false,
         date:'@guid',
         'deliveryp|1': ['男士餐','女士餐','工作餐'],
         address: '@ctitle(7,12)',
         'pay|1': ['已付款','未付款'],
         'deliverys|1': ['待配送','已配送','取消配送','配送失败'],
         'receiver|1':['李大宝','李师傅','张三'],
         phone:Mock.mock(/1\d{10}/),
         time: '@DATETIME("yyyy-MM-dd")',
       //   image: '@image(375x150,@color)',
       }],
       total:32,
       pageSize:5,
       
       })
       if (body.region) {
        let deliveryplist =['男士餐', '女士餐', '工作餐']
        deliveryplist=  deliveryplist.filter(item=>{
          return item.includes(body.region)
        })
        if(deliveryplist[0]){
          // @ts-ignore
          data.list = data.list.map((item) => {
           const num = Math.floor(Math.random()*deliveryplist.length)
            item.deliveryp = deliveryplist[num]
            return item
          })
          data.total *= deliveryplist.length/3
         
        }
     
      
    }
    if(body.name){
      if (!isNaN(body.name)) {
        // @ts-ignore
              data.list = data.list.map((item) => {
                item.phone = body.name
                return item
              })
              data.total *=0.5
            }else{ 
              let receiverlist =['张三','李四','李师傅','张师傅']
              receiverlist=  receiverlist.filter(item=>{
  
                return item.includes(body.name)
              })
              console.log(receiverlist)
              if(receiverlist[0]){
                // @ts-ignore
                data.list = data.list.map((item) => {
                 const num = Math.floor(Math.random()*receiverlist.length)
                  item.receiver = receiverlist[num]
                  return item
                })
                data.total *= receiverlist.length/3
               
              }
              else{
                data.list=[]
              }
        
        
             
            }
    }
    if(body.date1&&body.date2){
      let time1=body.date1
      let time2=body.date2
      let time3=Math.floor(time1+Math.random()*(time2-time1+1))
      let time4=new Date(time3)
      console.log(time4)
    console.log(time3)
        // @ts-ignore
        data.list = data.list.map((item) => {
          item.time = time4
          return item
        })
        data.total *= 0.5
    }
  return {
    data,
    code:200,
    message:'请求配送数据成功',
  }
})
